<template>
  <div class="app-container">
    <el-form label-width="120px">
      <el-form-item label="医院名称">
        <el-input v-model="hospitalSet.hosname"/>
      </el-form-item>
      <el-form-item label="医院编号">
        <el-input v-model="hospitalSet.hoscode"/>
      </el-form-item>
      <el-form-item label="api地址">
        <el-input v-model="hospitalSet.apiUrl"/>
      </el-form-item>
      <el-form-item label="联系人">
        <el-input v-model="hospitalSet.contactsName"/>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="hospitalSet.contactsPhone"/>
      </el-form-item>
      <el-form-item>
        <el-button :disabled="saveBtnDisabled" type="primary" @click="saveOrUpdate">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import hospset from "@/api/yygh/hospset";
export default {
  data() {
    return {
      hospsetId: "", //医院设置id
      hospitalSet: {}, //表单对象
      saveBtnDisabled: false //按钮是否不可操作
    };
  },
  created() {
    if (this.$route.params && this.$route.params.id) {
      console.log(this.$route.params.id);
      this.hospsetId = this.$route.params.id;
      hospset.getHospSetById(this.hospsetId).then(response => {
        this.hospitalSet = response.data.hospitalSet;
      });
    }
  },
  methods: {
    //保存方法
    saveOrUpdate() {
      if (this.hospitalSet.id) {
        //修改
        this.updateHospitalSet();
      } else {
        //新增
        this.saveHospitalSet();
      }
    },
    //新增
    saveHospitalSet() {
      this.saveBtnDisabled = true;
      hospset.save(this.hospitalSet).then(response => {
        this.$message({
          type: "success",
          message: "新增成功!"
        });
        this.saveBtnDisabled = false;
        this.$router.push({ path: "/hospset/list" });
      });
    },
    //修改
    updateHospitalSet() {
      this.saveBtnDisabled = true;
      hospset.update(this.hospitalSet).then(response => {
        this.$message({
          type: "success",
          message: "修改成功!"
        });
        this.saveBtnDisabled = false;
        this.$router.push({ path: "/hospset/list" });
      });
    }
  }
};
</script>
